target=target/riscv64gc-unknown-none-elf/release/rsos
default:
	@make run
clear:
	cargo clean
toolchains:
	@rustup target add riscv64gc-unknown-none-elf
	@cargo install cargo-binutils
	@rustup component add llvm-tools-preview
run:
	@make build
	@qemu-system-riscv64 ${target}
build:
	@cargo build ${mode}
release:
	@make build mode=--release
gdb:
	@rust-gdb -ex "file ${target}" -ex "set arch riscv:rv64" -ex "target remote localhost:1234"
lldb:
	@rust-lldb -o "file ${target}" -o "settings set target.default-arch riscv64" -o "gdb-remote 1234"
bin:
	@rust-objcopy --strip-all ${target} -O binary ${target}.bin
install:
	@make clear
	@make release
	@make bin
	@make stat
	@echo [RUNING...]
	@qemu-system-riscv64 -machine virt -nographic -bios asset/bootloader/rustsbi/rustsbi-qemu.bin -device loader,file=${target}.bin,addr=0x80200000 ${debug}
debug:
	@make install debug="-s -S"
stat:
	@make bin
	@stat ${target}
	@stat ${target}.bin
property:
	@file ${target}
head:
	@rust-readobj -h ${target}
dump:
	@rust-objdump -S ${target}